package com.quan.mall.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.quan.common.core.BaseService;
import com.quan.mall.entity.MallUserAddress;
import com.quan.mall.mapper.MallUserAddressMapper;
import com.quan.mall.service.MallUserAddressService;

/**
 * <p>
 * 电商-用户收货信息表 服务实现类
 * </p>
 *
 * @author 杨浩泉
 * @since 2018-11-18
 */
@Service
public class MallUserAddressServiceImpl extends BaseService<MallUserAddress> implements MallUserAddressService {
	
	@Autowired
	private MallUserAddressMapper mapper ;
	
	@Transactional
	@Override
	public MallUserAddress insertSelective(MallUserAddress entity) {
		
		if(entity.getDefault()) { //如果该条地址设为默认，则将已设为默认地址的改为非默认
			this.setDefault(entity.getUserId(), false);
    	}
		
		return super.insertSelective(entity);
	}
	
	@Override
	public int updateSelective(MallUserAddress entity) {
		
		if(entity.getDefault()) { //如果该条地址设为默认，则将已设为默认地址的改为非默认
			this.setDefault(entity.getUserId(), false);
    	}
		
		return super.updateSelective(entity);
	}

	@Override
	public void setDefault(Long userId, Boolean isDefault) {
		this.mapper.setDefault(userId, isDefault);
	}
	
}